<?php
$post = Post::findById($GLOBALS['post']);
$navArray = Navigator::findAll();
$linkArray = Link::findAll();
$categoryArray = Category::findAll();
$settings = Config::getInstance();
$tagArray = Tag::findAll();

$base = $settings->get('base');
$theme = $settings->get('theme');
$author = $post->getAuthor();
?><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title><?php echo $post->getTitle(), ' - ', $settings->get('title'); ?></title>
    <script src="<?php echo $base ?>/themes/<?php echo $theme ?>/scripts/html5.js"></script>
    <link  href="<?php echo $base ?>/themes/<?php echo $theme ?>/styles/normalize.css" rel="stylesheet" />
    <link  href="<?php echo $base ?>/themes/<?php echo $theme ?>/styles/article.css" rel="stylesheet" />
</head>
<body>
<header>
    <h1><span><a href="<?php echo $base; ?>"><?php echo $settings->get('title') ?></a></span></h1>

    <p><?php echo $settings->get('description') ?></p>
    <nav>
        <ul>
        <?php
        foreach ($navArray as /** @var $nav Navigator */ $nav) {
            echo sprintf('<li><a href="%s" target="%s">%s&nbsp;</a></li>', $nav->getHref() ? $nav->getHref() : $base, $nav->getTarget(), $nav->getName());
        }
        ?>
        </ul>
    </nav>
</header>
<div id="content-wrapper">
    <section>
        <article class="post blog-content">
            <header class="post-header">
                <h2><?php echo $post->getTitle() ?></h2>

                <p>
                <?php echo date('Y-m-d H:i:s', $post->getCreateTime()); ?> |
                <?php echo $author ?> |
                <a href="<?php echo $base ?>/post/<?php echo $post->getId() ?>.html#comments" title="查看评论"><?php echo count($post->getComments()) ?> Comments</a> |
                <?php
                    $categoryName = Category::findById($post->getCategory())->getName();
                echo sprintf('<a href="%s/category/%s.html" title="查看分类 %s 的全部文章">%s</a>', $base, $categoryName, $categoryName, $categoryName);

                if (count($post->getTags()) == 0) {
                } else {
                    echo ' | ';
                    foreach ($post->getTags() as $tag) {
                        echo sprintf('<a href="%s/tag/%s.html" title="所属标签 %s">%s</a>&nbsp;', $base, $tag, $tag, $tag);
                    }
                }
                ?></p>
            </header>
            <div>本文地址：<a href="<?php echo $base, '/post/', $post->getId(), '.html'; ?>"><?php echo $base, '/post/', $post->getId(), '.html'; ?></a></div>
            <div><?php echo $post->getContent(); ?></div>
            <footer class="post-footer">
                <div class="author-wrapper">
                    <p>Written by ishowshao</p>
                </div>
                <nav class="related-wrapper">
                    <h3>Related Posts</h3>
                </nav>
            </footer>
        </article>
        <section id="comments-wrapper">
            <div id="comments">
                <h2>评论</h2>
                <?php
                if (count($post->getComments()) == 0) {
                    echo '<article><p>暂无评论</p></article>';
                }
                foreach ($post->getComments() as /** @var $comment Comment */ $comment) {
                ?>
                <article>
                    <footer>
                        <?php
                        if ($comment->getWebsite()) {
                        ?>
                        <p>
                            <a href="<?php echo $comment->getWebsite() ?>" target="_blank" title="<?php echo $comment->getWebsite() ?>"><?php echo $comment->getAuthor() ?></a>
                        </p>
                        <?php
                        } else {
                        ?>
                        <p><?php echo $comment->getAuthor() ?></p>
                        <?php } ?>

                        <p>
                            <time datetime="<?php echo date('Y-m-d H:i:s', $comment->getCreateTime()) ?>"><?php echo date('Y-m-d H:i:s', $comment->getCreateTime()) ?></time>
                        </p>
                    </footer>
                    <p><?php echo htmlspecialchars($comment->getContent()) ?></p>
                </article>
                <?php
                }
                ?>
            </div>
            <div id="reply">
                <h2>发表评论：</h2>

                <form action="<?php echo $base ?>/admin/server/api/comment.php" method="POST">
                    <fieldset class="required">
                        <div>
                            <label for="author">昵称</label>
                            <input type="text" name="author" id="author" required="required" />
                        </div>
                        <div>
                            <label for="email">邮件地址</label>
                            <input type="text" name="email" id="email" />
                        </div>
                        <div>
                            <label for="website">个人主页</label>
                            <input type="text" name="website" id="website" value="http://" />
                        </div>
                    </fieldset>
                    <fieldset class="required">
                        <div>
                            <label for="content">内容</label>
                            <textarea id="content" name="content" required="required"></textarea>
                        </div>
                    </fieldset>
                    <fieldset>
                        <div>
                            <label for="code">验证码</label>
                            <input type="text" name="code" id="code" lang="<?php echo $base; ?>/admin/server/api/captcha.php" />
                        </div>
                    </fieldset>
                    <fieldset>
                        <div>
                            <input type="hidden" name="postId" value="<?php echo $post->getId() ?>" />
                            <input type="submit" value="发表评论" />
                        </div>
                    </fieldset>
                </form>
            </div>
        </section>
    </section>
    <aside>
        <nav>
            <h1>分类</h1>
            <ul>
                <?php foreach ($categoryArray as /** @var $category Category */ $category) { ?>
                <li><a href="<?php echo $base, '/category/', $category->getName(), '.html' ?>" title="查看 <?php echo $category->getName() ?> 的全部文章"><?php echo $category->getName() ?></a></li>
                <?php } ?>
            </ul>
        </nav>
        <nav class="tag-nav">
            <h1>标签</h1>
            <ul>
                <?php foreach ($tagArray as /** @var $tag Tag */ $tag) { ?>
                <li><a href="<?php echo $base, '/tag/', $tag->getName(), '.html' ?>"><?php echo $tag->getName() ?></a></li>
                <?php } ?>
            </ul>
        </nav>
        <nav>
            <h1>链接</h1>
            <ul>
                <?php foreach ($linkArray as /** @var $link Link */ $link) { ?>
                <li><a href="<?php echo $link->getHref() ?>" target="_blank" title="<?php echo $link->getDescription() ?>"><?php echo $link->getName() ?></a></li>
                <?php } ?>
            </ul>
        </nav>
    </aside>
</div>
<footer>
    <p>Powered by Paper Blog</p>
</footer>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="<?php echo $base ?>/themes/<?php echo $theme ?>/scripts/post.js"></script>
</body>
</html>
